package cn.com.dhcc.app.pub.core.job.tlq;

import javax.jms.Message;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.base.IocBean;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.consts.TlqConfig;
import cn.com.dhcc.turbo.entity.registry.NodeInfo;
import cn.com.dhcc.turbo.service.queue.tlq.TlqOptService;
import cn.com.dhcc.turbo.service.queue.tlq.listener.TlqLqMessageListener;
import cn.com.dhcc.turbo.service.registry.BaseInfoService;

/**
 * tlq消息消费定时任务
 * 
 * @日期 2015-5-26 上午10:01:54
 * @作者  高强
 */
public class RecvMessageJob  extends QuartzJobBean {
private Logger logger = Log.getLogger(LOGTYPE.QUARTZJOB);
	@Override
	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {
		BaseInfoService baseInfoService=(BaseInfoService) CM.getBeanByName(IocBean.BASE_INFO_SERVICEIMPL_BEAN);
		NodeInfo localNode;
		try {
			logger.info("定时任务RecvMessageJob开始执行....");
			localNode = baseInfoService.getCurrentNodeInfo();
			 if (localNode!=null) {//节点初始化后才开始定时任务
				 TlqOptService service=CM.getBean(TlqOptService.class);
					TlqLqMessageListener consumeService=CM.getBean(TlqLqMessageListener.class);
					//循环tlq本地队列，消费队列中的消息
					//取LQ_CM_DATA队列中的消息
					Message message=null;
					message=service.recvMessage(TlqConfig.LQ_CM_DATA);
					if (message!=null) {
						consumeService.onMessage(message);
					}
					//取LQ_CM_DATA_LOG队列中的消息
					message=service.recvMessage(TlqConfig.LQ_CM_DATA_LOG);
					if (message!=null) {
						consumeService.onMessage(message);
					}
					//取LQ_TEST队列中的消息
					message=service.recvMessage(TlqConfig.LQ_TEST);
					if (message!=null) {
						consumeService.onMessage(message);
					}
			 }
			 logger.info("定时任务RecvMessageJob执行结束....");
		} catch (ServiceException e) {
			logger.error("定时任务RecvMessageJob执行时报错:"+e);
		}
		

		
	}

}
